package com.playball.lottery.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.R.string;
import android.text.format.Time;
import android.util.Log;

public class DateUtil {

	/**
	 * now datetime(yyyy-MM-dd HH:mm:ss)
	 */
	public static String getFullDateTime() {
		SimpleDateFormat dfTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dateTemp = new Date();
		return dfTemp.format(dateTemp);
	}

	public static Date getDateTime() {
		SimpleDateFormat dfTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dateTemp = new Date();
		String str = dfTemp.format(dateTemp);
		Date date = null;
		try {
			date = dfTemp.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
		}
		return date;

	}

	/**
	 * datetime(yyyy-MM-dd HH:mm:ss) of datePara
	 */
	public static String getFullDateTime(Date datePara) {
		SimpleDateFormat dfTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return dfTemp.format(datePara);
	}

	/**
	 * now date(yyyy-MM-dd)
	 */
	public static String getDate() {
		SimpleDateFormat dfTemp = new SimpleDateFormat("yyyy-MM-dd");
		Date dateTemp = new Date();
		return dfTemp.format(dateTemp);
	}
	
	/**
	 * now year(yyyy)
	 */
	public static String getYear() {
		SimpleDateFormat dfTemp = new SimpleDateFormat("yyyy");
		Date dateTemp = new Date();
		return dfTemp.format(dateTemp);
	}

	/**
	 * date(yyyy-MM-dd) of datePara
	 */
	public static String getDate(Date datePara) {
		SimpleDateFormat dfTemp = new SimpleDateFormat("yyyy-MM-dd");
		return dfTemp.format(datePara);
	}

	/**
	 * now time(HH:mm:ss)
	 */
	public static String getTime() {
		SimpleDateFormat dfTemp = new SimpleDateFormat("HH:mm:ss");
		Date dateTemp = new Date();
		return dfTemp.format(dateTemp);
	}

	/**
	 * time(HH:mm:ss) of datePara
	 */
	public static String getTime(Date datePara) {
		SimpleDateFormat dfTemp = new SimpleDateFormat("HH:mm:ss");
		return dfTemp.format(datePara);
	}

	/**
	 * yyyyMMddHHmmss
	 */
	public static String getDateTime0(String date) {
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(date);
		} catch (ParseException pe) {
//			System.out.println(pe.getMessage());
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
		String str_date = sdf1.format(d);
		return str_date + "";
	}

	/**
	 * 
	 * @param date
	 * @return HH:mm
	 */
	public static String getDateTime1(String date) {
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(date);
		} catch (ParseException pe) {
//			System.out.println(pe.getMessage());
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm");
		String str_date = sdf1.format(d);
		return str_date + "";
	}

	/**
	 * 
	 * @param date
	 * @return MM-dd HH:mm
	 */
	public static String getDateTime2(String date) {
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(date);
		} catch (ParseException pe) {
//			System.out.println(pe.getMessage());
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd HH:mm");
		String str_date = sdf1.format(d);
		return str_date + "";
	}
	
	/**
	 * 
	 * @param date
	 * @return yyyy-MM-dd
	 */
	public static String getDateTime3(String date) {
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(date);
		} catch (ParseException pe) {
//			System.out.println(pe.getMessage());
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
		String str_date = sdf1.format(d);
		return str_date + "";
	}
	
	/**
	 * 
	 * @param date
	 * @return yyyy-MM-dd HH:mm
	 */
	public static String getDateTime4(String date) {
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(date);
		} catch (ParseException pe) {
//			System.out.println(pe.getMessage());
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String str_date = sdf1.format(d);
		return str_date + "";
	}
	
	/**
	 * 
	 * @param date
	 * @return MM-dd
	 */
	public static String getDateTime5(String date) {
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(date);
		} catch (ParseException pe) {
//			System.out.println(pe.getMessage());
		}
		SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd");
		String str_date = sdf1.format(d);
		return str_date + "";
	}
	
	/**
	 * 
	 * @param date
	 * @param days
	 * @return yyyy-MM-dd
	 */
	public static String getDateAfterDay(String date,int days){
		java.util.Date d = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = sdf.parse(date);
		} catch (ParseException pe) {
//			System.out.println(pe.getMessage());
		}
		
		long l = d.getTime();
		l = l + (days*24*60*60*1000l);
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
		d = new Date(l);
		return sdf1.format(d);
	}

	public static String getWeekName(int wk) {
		String res = null;
		switch (wk) {
		case 1:
			res = "周一";
			break;
		case 2:
			res = "周二";
			break;
		case 3:
			res = "周三";
			break;
		case 4:
			res = "周四";
			break;
		case 5:
			res = "周五";
			break;
		case 6:
			res = "周六";
			break;
		case 0:
			res = "周日";
			break;
		default:
			break;
		}
		return res;

	}
	
	public static String getWeekName7(String wk) {
		String res = null;
		if(wk.equals("1")){
			res = "周一";
		}else if(wk.equals("2")){
			res = "周二";
		}else if(wk.equals("3")){
			res = "周三";
		}else if(wk.equals("4")){
			res = "周四";
		}else if(wk.equals("5")){
			res = "周五";
		}else if(wk.equals("6")){
			res = "周六";
		}else if(wk.equals("7")){
			res = "周日";
		}
		return res;
	}

	public static String getGameNo(String mId) {
		String res = null;
		int i = Integer.parseInt(mId.substring(8, 9));
		switch (i) {
		case 1:
			res = "周一";
			break;
		case 2:
			res = "周二";
			break;
		case 3:
			res = "周三";
			break;
		case 4:
			res = "周四";
			break;
		case 5:
			res = "周五";
			break;
		case 6:
			res = "周六";
			break;
		case 7:
			res = "周日";
			break;
		default:
			break;
		}
		res += mId.substring(9, mId.length());
		return res;
	}
	
	/**
	 * 修改标题字符串 
	 * @param wId 原标题字符串  3 2013-07-17  共26场比赛可投注
	 * @return  中文周几标题字符串  res= 周三 2013-07-17  共26场比赛可投注
	 */
	public static String getTName(String wId) {
		String res = null;
		int i = Integer.parseInt(wId.substring(0, 1));
		switch (i) {
		case 1:
			res = "周一";
			break;
		case 2:
			res = "周二";
			break;
		case 3:
			res = "周三";
			break;
		case 4:
			res = "周四";
			break;
		case 5:
			res = "周五";
			break;
		case 6:
			res = "周六";
			break;
		case 7:
			res = "周日";
			break;
		default:
			break;
		}
		res += wId.substring(1, wId.length());
		return res;
	}

	public static String getJCLQWKName(String wId) {
		String res = null;
		int i = Integer.parseInt(wId.substring(0, 1));
		switch (i) {
		case 1:
			res = "周一";
			break;
		case 2:
			res = "周二";
			break;
		case 3:
			res = "周三";
			break;
		case 4:
			res = "周四";
			break;
		case 5:
			res = "周五";
			break;
		case 6:
			res = "周六";
			break;
		case 7:
			res = "周日";
			break;
		default:
			break;
		}
		return res;
	}
	
	/**
	 * 比较两个时间之间相差多少天
	 * 
	 * @param time1
	 *            "2013-05-29 13:31:40"
	 * @param time2
	 *            "2013-05-28 13:31:40"
	 * @return 1
	 */
	public static long getDiffTime(String time1, String time2) {
		long days = 0;
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date d1 = df.parse(time1);
			Date d2 = df.parse(time2);
			long diff = d1.getTime() - d2.getTime();
			days = diff / (1000 * 60 * 60 * 24);
		} catch (Exception e) {
		}
		return days;
	}
	
	/**
	 * 比较两个时间之间相差多少小时
	 * 
	 * @param time1
	 *            "2013-05-29 13:31:40"
	 * @param time2
	 *            "2013-05-28 13:31:40"
	 * @return 24
	 */
	public static long getDiffTime2(String time1, String time2) {
		long hours = 0;
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date d1 = df.parse(time1);
			Date d2 = df.parse(time2);
			long diff = d1.getTime() - d2.getTime();
			hours = diff / (1000 * 60 * 60 );
		} catch (Exception e) {
		}
		return hours;
	}
}